﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinForm_Bankapp
{
    public class CreditAccount : Account
    {
        private decimal creditLimit;//信用额度

        public decimal CreditLimit//返回信用额度
        {
            get { return creditLimit; }
        }

        public CreditAccount(string accountNumber, decimal initialBalance, decimal creditLimit)//构造函数
            : base(accountNumber, initialBalance)
        {
            this.creditLimit = creditLimit;
        }

        public override void Withdraw(decimal amount)//取钱
        {
            if (amount <= 0)
            {
                throw new ArgumentException("Amount must be greater than zero.");
            }

            decimal availableBalance = Balance + CreditLimit;

            if (availableBalance >= amount)
            {
                Balance -= amount;
            }
            else
            {
                throw new InsufficientBalanceException("Insufficient balance and credit limit.");
              
            }
        }

        public override void Deposit(decimal amount)
        {
            if (amount <= 0)
            {
                throw new ArgumentException("Amount must be greater than zero");
            }
            else
            {
                Balance += amount;
            }

        }
    }
}
